<?
require_once($r."_engine/table_editor/c_table_editor.php");

class CTableEditorAccounts extends CTableEditor
{
	function OnPrintData($f, &$v)
	{
		if (isset($f['num_of_monitors']))
		{
			$id = $v;
			$query = "SELECT COUNT(*) AS cnt FROM monitors WHERE account_id=$id.;";
			$res = execute_query($query);
			$row = @mysql_fetch_array($res);
			$v = @$row["cnt"];
			return;
		}
		if (@$f['name'] == "created")
		{
			/* TODO: use corresponding sql_table engine */
			$v = date("Y-m-d", strtotime($v));
			return;
		}
		$this->OnPrintDataStd($f, $v);
	}
}

$te_accounts = new CTableEditorAccounts();
$te_accounts->Init();
$te_accounts->table_name = "accounts";
$te_accounts->page_name  = "accounts";
$te_accounts->fields = 
	array(
		array('name'=>"id",				'title'=>"ID"),
		array('name'=>"created",		'title'=>"Created"),
		array('name'=>"email",			'title'=>"E-mail"),
		array('name'=>"email_bcc",		'title'=>"BCC"),
		array('name'=>"password",		'title'=>"Password"),
		array('name'=>"first_name",		'title'=>"First Name"),
		array('name'=>"last_name",		'title'=>"Last Name"),
		array('name'=>"id",				'title'=>"#Monitors",		'num_of_monitors'=>true),
	);
$te_accounts->order = "ORDER BY id ASC";
$te_accounts->allow_edit = true;

$te_accounts->buttons = array(
	$te_accounts->button_remove
);
?>